﻿// ============= 弹框方法 ==================
export const _layer = function(content) {
	layer.open({
		content: content,
		skin: "msg",
		time: 3,
		shift: 1,
		shadeClose: true
	});
}

//得到token
const token = localStorage.getItem('token');

// 王杰，杰哥(1099880690) 10:50:33
// 118.24.184.204:80


// const IP = "http://118.24.184:80";
const IP = "http://yydm.frpgz1.idcfengye.com?token=" + token;


//验证手机号正则
export const _checkMobile = function(sMobile) {
	let str = String(sMobile).trim();
	if (str.length == 11 && str.slice(0, 1) == "1") {
		return true;
	} else {
		_layer("请输入正确的手机号");
		return false;
	}
};

//转换时间戳
export const _date = function(timestamp) {
	if (!timestamp) {
		return "";
	}
	var date;
	//时间戳为10位需*1000，时间戳为13位的话不需乘1000
	if (String(timestamp).length == 10) {
		date = new Date(Number(timestamp) * 1000);
	}
	if (String(timestamp).length == 13) {
		date = new Date(Number(timestamp));
	}
	let Y = date.getFullYear() + "-";
	let M =
		(date.getMonth() + 1 < 10 ?
			"0" + (date.getMonth() + 1) :
			date.getMonth() + 1) + "-";
	let D = date.getDate() + " ";
	let h = date.getHours() + ":";
	let m = date.getMinutes() + ":";
	let s = date.getSeconds();
	return Y + M + D + h + m + s;
};

//钱分转换为元
export const _money = function(val) {
	let judge = String(val);
	if (judge == "undefined" || judge == "null") {
		return 0.0;
	}
	let priceStr = String(parseFloat(parseInt(val) / 100));
	let index = priceStr.indexOf(".");
	if (index != -1) {
		let handle = priceStr.slice(index + 1);
		if (handle.length == 1) {
			priceStr = priceStr + "0";
		}
	} else {
		priceStr = priceStr + ".00";
	}
	return priceStr;
};

//钱元转为分
export const _fen = function(val) {
	let str = String(val);
	let point = str.indexOf(".");
	if (point != -1) {
		let zhenshu = parseInt(str.slice(0, point)) * 100;
		let pointAfter = str.slice(point + 1);
		if (pointAfter.length == 1) {
			return zhenshu + parseInt(pointAfter) * 10;
		} else if (pointAfter.length >= 2) {
			return (
				zhenshu +
				parseInt(pointAfter.slice(0, 1)) * 10 +
				parseInt(pointAfter.slice(1, 2))
			);
		} else {
			return zhenshu;
		}
	} else {
		return parseFloat(val) * 100;
	}
};

//得到参数
export const _gethash = function(val) {
	// val样板:window.location.href.slice(window.location.href.indexOf('?'))
	// 返回：
	// {
	//   a:"jhgdsjkfasdfa"
	//   data:"%5B%7B%22goodsNum%22%3A%22191942513806708736%22%2C%22count%22%3A1%2C%22specNum%22%3A%22191942514490380289%22%7D%5D"
	// }
	var arr = val.replace(/^\?/, "").split("&");
	var params = {};
	for (var i = 0; i < arr.length; i++) {
		var data = arr[i].split("=");
		if (data.length == 2) {
			params[data[0]] = data[1];
		}
	}
	return params;
};


//首页
export const INDEX_DATA = IP + '/wechat/HomePageController/loadHomePage';

//商品详情
export const GOODS_INFO = IP + '/wechat/GoodsDetailedController/getGoodsByArrId';

//添加减少商品
export const GOODS_COUNT = IP + '/wechat/GoodsDetailedController/getPriceByGoodsIdAndGoodsNum';

//查商品数量
// export const GOODS_SHULIANG = IP + '/wechat/ShopCarController/getShopCarByGoodsId';

//得到购物车数据
export const CAR_COUNT = IP + '/wechat/GoodsDetailedController/getShopCarByUserId';

//左边类型数据
export const LEIXIN = IP + '/wechat/TypeDetailedController/loadTypeClass';

//点击类型进去的页面
export const GOLEIXIN = IP + '/wechat/TypeDetailedController/getArrDoByTypeId';

//保存地址
export const SAVE_ADDRESS = IP + '/wechat/AddressinfoController/save';

//预支付
export const ORDER_SUBMIT = IP + '/wechat/ShopCarController/loadShopCar';

//拉取地址 
export const GET_ADDRESS = IP + '/wechat/AddressinfoController/loadUserAddres';

//保存地址
export const SAVA_ADDRESS = IP + '/wechat/AddressinfoController/save';

//修改地址
export const EDIT_ADDRESS = IP + '/wechat/AddressinfoController/edit';

//支付
export const PAY = IP + '/wechat/pay/wxOrderPay';

//授权
export const SHOU = IP + '/wechat/AuthorizationController/wxUserAuthorization';